Subject: Re: malloc(0)
From: [email-masked] (Clive D.W. Feather)
Date: Mon, 28 Feb 1994 08:46:58 GMT
Newsgroups: comp.lang.c

In article <[email-masked]> [email-masked] (Paul L Fagerburg) writes:
> What's the big deal about malloc(0)? It's really considered bad
> programming style. The ANSI definition defines malloc(0) to return
> a NULL pointer; it's that simple. Nobody on God's green earth
> needs to allocate 0 bytes for use; it's usally to catch that one
> exception that really shouldn't happen anyway if you're writing
> clean code.

Gack, another idiot on the loose.

The ISO and ANSI standards both defined malloc(0) to be *either* NULL
*or* a unique pointer (and there's a separate issue as to what "unique"
means in this context, but I won't go into it).

While malloc(0) might not appear useful, being able to go realloc(ptr,0)
is. Any code that dynamically resizes a buffer can potentially use it.

-- 
Clive D.W. Feather     | Santa Cruz Operation    | If you lie to the compiler,
[email-masked]          | Croxley Centre          | it will get its revenge.
Phone: +44 923 816 344 | Hatters Lane, Watford   |   - Henry Spencer
Fax:   +44 923 210 352 | WD1 8YN, United Kingdom |